#include "trap.h"
   .set noat                # 禁止使用$at寄存器
   .globl main
   .text

main: 
    # 初始化寄存器
    lui     $s0, 0xFFFF          # $s0 = 0xFFFF0000
    lui     $s1, 0x7FFF          # $s1 = 0x7FFF0000
    lui     $t1, 0x80FF          # $t1 = 0x80FF0000
    lui     $s2, 0xFEFF          # $s2 = 0xFEFF0000
    lui     $s3, 0x00FF          # $s3 = 0x00FF0000

    # 设置低16位
    ori     $t1, $t1, 0x0008     # $t1 = 0x80FF0008
    lui     $t3, 0xFFFF          # $t3 = 0xFFFF0000
    ori     $t3, $t3, 0xFFFE     # $t3 = 0xFFFF0000 | 0xFFFE = 0xFFFFFFFE
    ori     $v1, $zero, 0x0010   # $v1 = 0x00000010

    # 加法操作调整值
    addiu   $s0, $s0, 0xFFFF     # $s0 = 0xFFFFFFFF
    addiu   $s1, $s1, 0xFFFF     # $s1 = 0x7FFFFFFF
    addiu   $t1, $t1, 0x8000     # $t1 = 0x80FF8008
    addiu   $s2, $s2, 0xFFFF     # $s2 = 0xFEFFFFFF
    addiu   $s3, $s3, 0x8001     # $s3 = 0x00FF8001

    # 逻辑左移、右移操作
    sll     $s2, $s0, 0x4        # $s2 = $s0 << 4 = 0xFFFFFFF0
    sll     $s3, $s0, 0x1F       # $s3 = $s0 << 31 = 0x80000000
    sra     $s2, $t1, 0x4        # $s2 = $t1 >> 4 (算术右移) = 0xF80FF800
    sra     $s3, $t1, 0x1F       # $s3 = $t1 >> 31 (算术右移) = 0xFFFFFFFF
    srl     $s2, $s1, 0x4        # $s2 = $s1 >> 4 (逻辑右移) = 0x07FFFFFF
    srl     $s3, $s1, 0x1F       # $s3 = $s1 >> 31 (逻辑右移) = 0x00000000

    # 变量移位操作
    sllv    $t4, $t3, $t1        # $t4 = $t3 << ($t1 & 31)
    sllv    $t5, $t3, $v1        # $t5 = $t3 << ($v1 & 31)
    srav    $t6, $t3, $t1        # $t6 = $t3 >> ($t1 & 31) (算术右移)
    srlv    $t7, $t3, $t1        # $t7 = $t3 >> ($t1 & 31) (逻辑右移)

    # 程序结束
    HIT_GOOD_TRAP                # 停止模拟器